//
// Created by Ge on 2024/3/5.
// glDrawArrays顶点法，根据我们传入的点去一个一个的绘制
// glDrawElements索引法，根据我们传入的索引序列，去顶点序列中寻找对应的顶点
//
#include "include/CourseTwo.h"
#include "include/SimpleCube.h"
#include "include/AngleCube.h"
#include <jni.h>
#include <GLES2/gl2.h>
#include <string.h>
#include <stdlib.h>
#include "include/LogUts.h"
#include "include/ShareLoader.h"
#include "math.h"
#include "include/glm/glm.hpp"
#include "include/glm/gtc/matrix_transform.hpp"
#include "include/glm/gtc/type_ptr.hpp"

#ifndef COURSE_TWO_REGISTER_CLASS
#define COURSE_TWO_REGISTER_CLASS "com/ziya/android/a3dmodel/nativelib/CourseTwoNative"
#endif
JNINativeMethod methods[] = {
        {"drawCube",                "()V",   (void *) &drawCube},
        {"drawCubeAngle",           "()V",   (void *) &drawCubeAngle},
        {"angleCubeSurfaceChanged", "(II)V", (void *) &angleCubeSurfaceChanged},
        {"onSurfaceCreated", "()V", (void *) &onSurfaceCreated},
};

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
    JNIEnv *env;
    if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
        return -1;
    }
    jclass clz = env->FindClass(COURSE_TWO_REGISTER_CLASS);
    env->RegisterNatives(clz, methods, sizeof(methods) / sizeof(JNINativeMethod));
    env->DeleteLocalRef(clz);
    return JNI_VERSION_1_6;
}

JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
    JNIEnv *env = NULL;
    if (JNI_OK != vm->GetEnv((void **) &env, JNI_VERSION_1_6)) {
        return;
    }
    jclass clz = env->FindClass(COURSE_TWO_REGISTER_CLASS);
    env->UnregisterNatives(clz);
    env->DeleteLocalRef(clz);
}

static SimpleCube simpleCube = SimpleCube();
static AngleCube angleCube = AngleCube();

/**
 * 正面显示长方体，因此只能看到一个面
 * @param env
 * @param thiz
 */
void drawCube(JNIEnv *env, jobject thiz) {
    simpleCube.draw();
}

/**
 * 从某个角度查看长方体
 * @param env
 * @param thiz
 */
void drawCubeAngle(JNIEnv *env, jobject thiz) {
    angleCube.draw();
}


void angleCubeSurfaceChanged(JNIEnv *env, jobject thiz, jint width, jint height) {
    angleCube.onSurfaceChanged(width, height);
}

void onSurfaceCreated(JNIEnv *env, jobject thiz){
    angleCube.onSurfaceCreated();
}



